package dianmobile.eistarandroid.network.request;

import android.content.Context;

import com.android.volley.Response;

import org.xmlpull.v1.XmlPullParser;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import dianmobile.eistarandroid.utils.ConstantsData;

/**
 * Created by dianmobile_yy on 15/10/9.
 */
public class MyFriendsRequest extends ByhhAndroidRequest {

    public static void execute(Context context, RequestCallback callback) {
        executeSuper(context, RequestType.MY_FRIENDS, null, callback);
    }

    public MyFriendsRequest(int method, String url, Map<String, String> params, RequestCallback callback, Response.ErrorListener listener) {
        super(method, url, params, callback, listener);
    }

    @Override
    protected void parseXmlToMap(XmlPullParser parser, Map<String, Object> map) {
        final String TAG_FRIENDS = "friends";
        final String TAG_FRIEND = "friend";
        final String TAG_USERID = "userid";
        final String TAG_REMARK = "remark";

        List<String> result = new ArrayList<>();

        try {
            int event = parser.getEventType();
            while (event != XmlPullParser.END_DOCUMENT) {
                switch (event){
                    case XmlPullParser.START_DOCUMENT:
                        break;
                    case XmlPullParser.START_TAG:
                        String tagName = parser.getName();
                        if (tagName.equals(TAG_FRIENDS)){
                            result.clear();
                        } else if(TAG_USERID.equals(tagName)){
                            result.add(parser.nextText());
                        }
                        break;
                    default:
                        break;
                }
                event = parser.next();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        map.put(ConstantsData.MY_FRIENDS, result);
    }
}
